Imports System.Data.SqlClient
Imports System.Data, System.Data.OleDb
Public Class FrmSearchUpdateDelete
    Dim AcDs As New DataSet, Str As String
    Dim Dt As New DataTable
    Private viewAc As New DataView

    Private Sub FrmSearchUpdateDelete_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
      

        EnbX()
        Rd2.Checked = True
        Cmb1.Items.Clear()
        Str = "SELECT DISTINCT name1 FROM Table1 ORDER  BY NAME1 ASC;"

        AcDs = Datamanager.FillDataSet(AcDs, Str, "Table1")
        If Me.BindingContext(AcDs, "Table1").Count = 0 Then
            Exit Sub
        Else
            For I As Integer = 0 To AcDs.Tables("Table1").Rows.Count - 1
                Cmb1.Items.Add(AcDs.Tables("Table1").Rows(I).Item("name1"))
            Next
        End If

    End Sub
    Private Sub EnbX()
        Dim I As Integer
        For I = 0 To Me.Controls.Count - 1
            If TypeOf Me.Controls(I) Is Button Then
                Me.Controls(I).Enabled = False
            End If
        Next
        Cmb1.Focus()
    End Sub
    Sub DVF(ByVal STRFILTER As String)

        viewAc = Dt.DefaultView
        If Rd1.Checked = True Then
            viewAc.RowFilter = "name1 Like '" & STRFILTER & "%'"
        End If
        If Rd2.Checked = True Then
            viewAc.RowFilter = "name1 Like '%" & STRFILTER & "%'"
        End If
        If Rd3.Checked = True Then
            viewAc.RowFilter = "name1 Like '%" & STRFILTER & "'"
        End If

        fillGrid()
    End Sub
    Private Sub fillGrid()
        DGRD.Rows.Clear()
        For I As Integer = 0 To viewAc.Count - 1
            With viewAc.Item(I)
                Dim SUB_NO As String = .Item("num")
                Dim MID_NAME As String = .Item("NAME1")
                Dim SUB_NAME As String = .Item("iii")
                Dim SUB_INITIAL_BALANCE_C As String = .Item("hfadat")
                Dim SUB_INITIAL_BALANCE_D As String = .Item("Sex")

                Dim row As String() = {SUB_NO, MID_NAME, SUB_NAME, _
                            SUB_INITIAL_BALANCE_C, SUB_INITIAL_BALANCE_D, "", ""}

                DGRD.Rows.Add(row)

            End With
        Next
    End Sub

    Private Sub DGRD_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DGRD.CellContentClick
        Try
            'UPDATE
            If e.ColumnIndex = 5 Then
                With DGRD.CurrentRow
                    Dim SUB_No As Integer = .Cells(0).Value
                    Dim SUB_NAME As String = .Cells(2).Value
                    Dim I_C As Double = .Cells(3).Value
                    Dim I_D As Double = .Cells(4).Value
                    Datamanager.UpdateAccount(SUB_No, SUB_NAME, I_C, I_D)
                End With
                MsgBox("  ")
            End If
            'DELETE
            If e.ColumnIndex = 6 Then
                If MsgBox("    ", MsgBoxStyle.OkCancel) = MsgBoxResult.Cancel Then
                    Exit Sub
                End If
                With DGRD.CurrentRow
                    Dim SUB_No As Integer = .Cells(0).Value
                    Datamanager.RemoveAccount(SUB_No)

                    'remove row from datagrid
                    Dim ROW As DataGridViewRow = DGRD.CurrentRow
                    DGRD.Rows.Remove(ROW)
                End With
                MsgBox("  ")
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    Private Sub CmdSaveAll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdSaveAll.Click
        For I As Integer = 0 To DGRD.Rows.Count - 2
            With DGRD.Rows(I)
                Dim SUB_No As Integer = .Cells(0).Value
                Dim SUB_NAME As String = .Cells(2).Value
                Dim I_C As Double = .Cells(3).Value
                Dim I_D As Double = .Cells(4).Value
                Datamanager.UpdateAccount(SUB_No, SUB_NAME, I_C, I_D)
            End With
        Next
    End Sub

    Private Sub DGRD_CellEndEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DGRD.CellEndEdit
        CmdSaveAll.Enabled = True
    End Sub
    Private Sub vld()
        Dim Sarry As String() = {".", "", "", "", "", "", "", "", "", "", "", _
        "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", _
        "", "", "", "", "", "", "", "", ""}
        Dim Carry As New ArrayList
        Dim S As String
        EnbX()
        For Each S In Sarry
            If Rd1.Checked = True Then
                viewAc.RowFilter = "name1 Like '" & S & "%'"
            End If
            If Rd2.Checked = True Then
                viewAc.RowFilter = "name1 Like '%" & S & "%'"
            End If
            If Rd3.Checked = True Then
                viewAc.RowFilter = "name1 Like '%" & S & "'"
            End If
            If viewAc.Count > 0 Then
                Carry.Add(S)
            End If
        Next
        For I As Integer = 0 To Me.Controls.Count - 1
            If TypeOf Me.Controls(I) Is Button Then
                Dim obj As [Object]
                For Each obj In Carry
                    If Me.Controls(I).Text = obj Then
                        Me.Controls(I).Enabled = True
                        Me.Button31.Enabled = True
                    End If
                Next obj
            End If
        Next

    End Sub
    Private Sub Cmb1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cmb1.SelectedIndexChanged
        Try
            Str = "select NAME1,num,Sex,iii,hfadat from Table1 where NAME1 = '" & Trim(Cmb1.Text) & "'order by NAME1"
            Datamanager.fillTable(Dt, Str)
            viewAc = Dt.DefaultView
            DVF("")
        Catch ex As Exception
            MsgBox(ex.Message)
            Exit Sub
        End Try
        vld()
    End Sub

    Private Sub Rd1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Rd1.CheckedChanged
        vld()
    End Sub

    Private Sub Rd3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Rd3.CheckedChanged
        vld()
    End Sub

    Private Sub Rd2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Rd2.CheckedChanged
        vld()
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        DVF("")
    End Sub

    Private Sub Button35_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button35.Click
        DVF("")
    End Sub

    Private Sub Button32_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button32.Click
        DVF("")
    End Sub

    Private Sub Button33_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button33.Click
        DVF("")
    End Sub

    Private Sub Button34_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button34.Click
        DVF("")
    End Sub
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        DVF("")
    End Sub
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        DVF("")
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        DVF("")
    End Sub

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        DVF("")
    End Sub

    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        DVF("")
    End Sub

    Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
        DVF("")
    End Sub

    Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
        DVF("")
    End Sub

    Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
        DVF("")
    End Sub

    Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
        DVF("")
    End Sub

    Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click
        DVF("")
    End Sub

    Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button12.Click
        DVF("")
    End Sub

    Private Sub Button13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button13.Click
        DVF("")
    End Sub

    Private Sub Button14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button14.Click
        DVF("")
    End Sub

    Private Sub Button15_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button15.Click
        DVF("")
    End Sub

    Private Sub Button16_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button16.Click
        DVF("")
    End Sub

    Private Sub Button17_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button17.Click
        DVF("")
    End Sub

    Private Sub Button18_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button18.Click
        DVF("")
    End Sub

    Private Sub Button19_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button19.Click
        DVF("")
    End Sub

    Private Sub Button20_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button20.Click
        DVF("")
    End Sub

    Private Sub Button21_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button21.Click
        DVF("")
    End Sub

    Private Sub Button22_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button22.Click
        DVF("")
    End Sub

    Private Sub Button23_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button23.Click
        DVF("")
    End Sub

    Private Sub Button24_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button24.Click
        DVF("")
    End Sub

    Private Sub Button25_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button25.Click
        DVF("")
    End Sub

    Private Sub Button26_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button26.Click
        DVF("")
    End Sub

    Private Sub Button27_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button27.Click
        DVF("")
    End Sub

    Private Sub Button28_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button28.Click
        DVF("")
    End Sub

    Private Sub Button29_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button29.Click
        DVF("")
    End Sub

    Private Sub Button30_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button30.Click
        DVF("")
    End Sub
    Private Sub Button36_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button36.Click
        DVF(".")
    End Sub
    Private Sub Button31_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button31.Click
        DVF("")
    End Sub

    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
        DVF(Trim(TextBox1.Text))
    End Sub
End Class